#ifndef BATSCRIPT_H
#define BATSCRIPT_H
#include <QByteArray>
#include <QStringList>
class BatScript
{
public:
    BatScript();
    static QByteArray creatBatScript(QByteArray smbDirFileName, QByteArray smbNameFileName, QByteArray outputFile,
                                     QByteArray logFile, QByteArray tmpFile, QByteArray finish)
    {
        QByteArray output = "chcp 65001"
                            "\n@echo off"
                            "\nsetlocal enabledelayedexpansion"
                            "\nset count=0"
                            "\nset index=0"
                            "\nset indexTmp=0"
                            "\nset smbNameList="
                            "\nset smbDirList="
                            "\nset winDirList="
                            "\nset conver="
                            "\nset conver2="
                            "\nset realPathList="
                            "\nset tmpFile="
                            + tmpFile + "\nset finishFile=" + finish + "\nset outputFile=" + outputFile
                            + "\nset logFile=" + logFile + "\nfor /f \"usebackq delims=\" %%a in (`type \""
                            + smbNameFileName
                            + "\"`) do (set smbNameList=!smbNameList!%%a)"
                              "\nfor /f \"usebackq delims=\" %%a in (`type \""
                            + smbDirFileName
                            + "\"`) do (set smbDirList=!smbDirList!%%a)"
                              "\ndate /T >%logFile%"
                              "\necho [SmbMap] > %outputFile%"
                              "\nfor %%s in (%smbNameList%) do ("
                              "\n  set conver=%%s"
                              "\n  set conver=!conver::= !"
                              "\n  set count=0"
                              "\n  for /f \"skip=1 tokens=1,* delims= \" %%a in ('net share \"!conver!\"') do ("
                              "\n    if !count! equ 0 ("
                              "\n        set conver2=%%b"
                              "\n        set conver2=!conver2: =:conver:!"
                              "\n        set winDirList=!winDirList! !conver2!"
                              "\n        set /a count+=1"
                              "\n        echo !conver! - : - %%b >> %outputFile%"
                              "\n    )"
                              "\n  )"
                              "\n)"
                              "\necho ==========smbDirList========== >>%logFile%"
                              "\necho %smbDirList% >>%logFile%"
                              "\necho ==========smbNameList========== >>%logFile%"
                              "\necho %smbNameList% >>%logFile%"
                              "\necho ==========smbNameOfDirList========== >>%logFile%"
                              "\necho %winDirList% >>%logFile%"
                              "\necho [FileList] >> %outputFile%"
                              "\necho ==========getRealDir========== >>%logFile%"
                              "\nfor %%s in (%smbDirList%) do ( "
                              "\n  set conver=%%s"
                              "\n  set conver=!conver::= !"
                              "\necho 1 dirSmbPath: !conver! >>%logFile%"
                              "\n  for /f \"tokens=1,2 delims=\\\" %%a in (\"!conver!\") do ("
                              "\n    set index=0"
                              "\n    set count=0"
                              "\n    if !count! equ 0 ("
                              "\necho 2 dirOfSmbName: %%a >>%logFile%"
                              "\n      for %%n in (%smbNameList%) do ("
                              "\n        set conver=%%n"
                              "\n        set conver=!conver::= !"
                              "\necho 3 smbName: %%a = !conver! >>%logFile%"
                              "\n        if %%a equ !conver! ("
                              "\necho 4 contains: %%a >>%logFile%"
                              "\n          set indexTmp=0"
                              "\n          for %%j in (%winDirList%) do ("
                              "\n            if !index! equ !indexTmp! ("
                              "\n            set conver2=%%b"
                              "\n            set conver2=!conver2: =:conver:!"
                              "\necho 5 dirOfRealPath: %%j\\!conver2! >>%logFile%"
                              "\n              set realPathList=!realPathList! %%j\\!conver2!"
                              "\n            )"
                              "\n            set /a indexTmp+=1"
                              "\n          )"
                              "\n        )"
                              "\n        set /a index+=1"
                              "\n      )"
                              "\n    )"
                              "\n    set /a count+=1"
                              "\n  )"
                              "\n)"
                              "\necho ==========realPathList========== >>%logFile%"
                              "\necho %realPathList% >>%logFile%"
                              "\necho ==============getFileName============== >>%logFile%"
                              "\ndel %tmpFile%"
                              "\nfor %%z in (%realPathList%) do ("
                              "\n    set conver=%%z"
                              "\n    set conver=!conver::conver:= !"
                              "\necho !conver! >>%logFile%"
                              "\n    dir \"!conver!\" /a-d/s/b>>%tmpFile%"
                              "\n)"
                              "\nsetlocal disabledelayedexpansion"
                              "\nfor /f \"tokens=*\" %%f in (%tmpFile%) do ("
                              "\n    echo %%f"
                              "\n    echo %%f - : - %%~zf >> %outputFile%"
                              ")"
                              "\ndel %tmpFile%"
                              "\necho . >%finishFile%"
                              "\necho ==============end============== >>%logFile%"
                              "\nexit b/";
        return output;
    }
};
#endif // BATSCRIPT_H
